<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title>Document</title>
</head>

<body>
    <input type='button' onclick='save_sess_item()' value='存值sess' 　/>
    <input type='button' onclick='get_sess_item()' value='取值sess' 　/>
    

    <input type='button' onclick='set_item()' value='存值local' 　/>
    <input type='button' onclick='get_item()' value='取值local' 　/>
    <input type='button' onclick='delete_item()' value='删除' 　/>
    <script>
    function save_sess_item(){
      // sessionStorage.setItem('key', 'value');
        var userSess = {};
        userSess.name = 'MrsHunag';
        userSess.age = 27;
        userSess.home = 'CH';
        sessionStorage.setItem('userinfoSess', JSON.stringify(userSess));
    }
    function get_sess_item(){
        var data = sessionStorage.getItem('userinfoSess');
        console.log("----data",data)
    }
    


    //localStorage 存值永久有效  
    function set_item() {
        var user = {};
        user.name = 'MrGu';
        user.age = 27;
        user.home = 'USA';
        localStorage.setItem('userinfo', JSON.stringify(user));
    }

    //localStorage取值  
    function get_item() {
        var data = JSON.parse(localStorage.getItem('userinfo'));
        var data1 = localStorage.getItem('userinfo');

        // var data = JSON.parse(localStorage.getItem('userinfo'));
        console.log("-----",data)
        console.log("-----",data1)
        // alert("name:" + data.name + "\r age:" + data.age + "\r home:" + data.home);
    }

    //localStorage删除指定键对应的值  
    function delete_item() {
        localStorage.removeItem('userinfo');
        alert(localStorage.getItem('userinfo'));
    }
    </script>
</body>

</html>